package com.atguigu.gmall.web.all.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.item.SkuItemFeignClient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

@Controller//需要跳转页面，所以不用RestController
public class SkuItemController {

    @Autowired
    SkuItemFeignClient skuItemFeignClient;

    @GetMapping("/{skuId}.html")
    public String getSkuInfo(@PathVariable("skuId") Long skuId, Model model){
        //把当前sku的所有数据交给页面
        //Result<Map<String, Object>> item = skuItemFeignClient.getItem(skuId);
        Result item = skuItemFeignClient.getItem(skuId);
        Map<String, Object> data = (Map<String, Object>) item.getData();
        //把远程调用得到的所有内容全部交给model，放在页面的请求中
        model.addAllAttributes(data);
        return "item/index";
    }
}
